package com.hamster.crmpre.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hamster.crmpre.mapper.EmployeePerformanceMapper;
import com.hamster.crmpre.pojo.EmployeePerformance;
import com.hamster.crmpre.service.EmployeePerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author ：Lizhipeng
 * @date ：Created in 2019/12/25 10:42
 * @description：员工业绩接口实现类
 * @modified By： Lizhipeng
 * @version: 1.0$
 */
@Service
public class EmployeePerformanceServiceImpl implements EmployeePerformanceService {

    @Autowired
    private EmployeePerformanceMapper employeePerformanceMapper;

    @Override
    public void insert(EmployeePerformance employeePerformance) {

    }

    /**
     * 根据executive_id查询员工业绩信息
     * @param executiveId 上级主管id
     * @return 员工业绩信息
     */
    @Override
    public List<EmployeePerformance> list(String executiveId) {
        QueryWrapper<EmployeePerformance> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("executive_id",executiveId).orderByDesc("input_time");
        return employeePerformanceMapper.selectList(queryWrapper);
    }

    @Override
    public void update(EmployeePerformance employeePerformance) {

    }

    @Override
    public void delete(List<String> ids) {

    }

    /**
     * 根据用户id获得员工业绩
     * @param userId 用户id
     * @return 一条员工业绩
     */
    @Override
    public EmployeePerformance get(String userId) {
        return employeePerformanceMapper.selectById(userId);
    }

    /**
     * 根据userId和time获得员工业绩
     * @param userId 个人id
     * @param time 时间
     * @return
     */
    @Override
    public List<EmployeePerformance> getByTime(String userId, Date time) {
        QueryWrapper<EmployeePerformance> queryWrapper = new QueryWrapper<>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        cal.add(Calendar.MONTH,1);
        Date nextMonthTime = cal.getTime();
        queryWrapper.eq("employee_id", userId);
        queryWrapper.ge("create_time", time).lt("create_time", nextMonthTime);
        return employeePerformanceMapper.selectList(queryWrapper);
    }
}
